package com.example.tiantian.process;

import com.example.tiantian.BaseActivity;
import com.example.tiantian.R;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class NewProcessActivity extends BaseActivity implements OnClickListener {
    TextView btnProcess;
    TextView btnInfo;

    FragmentManager fm;

    boolean isInfo;

    ProcessFragment fProcess;
    HardwareFragment fHardware;

    @Override
    protected void init() {
        setContentView(R.layout.activity_fragment);

        btnProcess = (TextView) findViewById(R.id.fragment1);
        btnInfo = (TextView) findViewById(R.id.fragment2);

        fProcess = new ProcessFragment();
        fHardware = new HardwareFragment();

        isInfo = false;

        fm = getFragmentManager();
    }

    @Override
    protected void loadData() {

        btnProcess.setText(R.string.process_manager);
        Drawable process = getResources().getDrawable(R.drawable.phone_speed);
        process.setBounds(0, 0, process.getMinimumWidth(), process.getMinimumWidth());
        btnProcess.setCompoundDrawables(null, process, null, null);
        btnProcess.setCompoundDrawablePadding(5);

        btnInfo.setText(R.string.process_hardware_info);
        Drawable info = getResources().getDrawable(R.drawable.phone_sys);
        info.setBounds(0, 0, info.getMinimumWidth(), info.getMinimumWidth());
        btnInfo.setCompoundDrawables(null, info, null, null);
        btnInfo.setCompoundDrawablePadding(5);

    }

    @Override
    protected void event() {
        btnProcess.setOnClickListener(this);
        btnInfo.setOnClickListener(this);

        changeFragment();
    }

    @Override
    public void onClick(View v) {
        isInfo = v.getId() == R.id.fragment2;
        changeFragment();
    }

    private void changeFragment() {
        FragmentTransaction ft = fm.beginTransaction();
        ft.replace(R.id.content, isInfo ? fHardware : fProcess);
        ft.commit();
        btnProcess.setEnabled(isInfo);
        btnInfo.setEnabled(!isInfo);

    }
}
